import { useCounterStore } from '@/stores/counter'
import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'login',
      component:() => import('../views/LoginPage.vue')
    },
    {
      path: '/dashbord',
      name: 'dashbord',
      component: () => import('../views/Dashbord.vue'),
      children:[
        {
          path: 'adminsterUser',
          name: 'adminsterUser',
          component: () => import('../views/AdminsterUser.vue'),
        },
        {
          path: 'Userdetail/:id',
          name: 'Userdetail',
          component: () => import('../views/UserDeail.vue'),
        },
        {
          path: 'Activity',
          name: 'Activity',
          component: () => import('../views/Activity.vue'),
        },
        {
          path: 'Activity/Add',
          name: 'ActivityAdd',
          component: () => import('../views/ActivityAdd.vue'),
        },
        {
          path: 'Activity/edit/:id',
          name: 'Activityedit',
          component: () => import('../views/ActivityAdd.vue'),
        },
        {
          path: 'Activity/detail/:id',
          name: 'Activitydetail',
          component: () => import('../views/ActivityDetail.vue'),
        },
        {
          path: 'Clue',
          name: 'Clue',
          component: () => import('../views/Clue.vue'),
        },
        {
          path: 'ClueAdd',
          name: 'ClueAdd',
          component: () => import('../views/ClueAdd.vue'),
        },
        {
          path: 'ClueEdit/:id',
          name: 'ClueEdit',
          component: () => import('../views/ClueAdd.vue'),
        }
      ]

    }
    
  ]
})
router.beforeEach((to, from) => {
  const status=useCounterStore()
  if(to.name==="login")
  {
    return true
  }
  console.log(status.loginstatus)
  if(!status.loginstatus){
    return { name: 'login'}
  }
})

export default router
